using UnityEngine;
using UnityEngine.UI;
using YooAsset;

public class DataToolTester : MonoBehaviour
{
    public Text testtext,text_3;
    public Button jumpBtn;
    public Image test_img;
    private const string image_name = "quanlity_2";
    void Start()
    {

        BasePveSkillDataTool skillDataTool = DataToolManager.Instance.GetDataTool<BasePveSkillDataTool>();
        skillDataTool.DataLoaded += OnSkillDataLoaded;
        skillDataTool.LoadData(Defines.BasePveSkillJsonPath);

        UserEmployerDataTool useremployeTool = DataToolManager.Instance.GetDataTool<UserEmployerDataTool>();
        useremployeTool.DataLoaded += OnUserDataLoaded;
        useremployeTool.LoadData(Defines.UserEmployeJsonPath);

        jumpBtn.onClick.AddListener(JumpToUIscene);
        this.LoadImage();
    }

    private void LoadImage()
    {
        var imgResTest = YooAssets.LoadAssetAsync<Sprite>(image_name);
        imgResTest.Completed += (AssetHandle handle) =>
        {
            test_img.sprite = handle.AssetObject as Sprite;
        };
    }

    private void JumpToUIscene()
    {
        
        GameObject.FindWithTag("LoadCanvas").GetComponent<SceneManager>().OpenScene(Defines.TestUIScene);
    }

    private void OnSkillDataLoaded()
    {
        BasePveSkillDataTool skillDataTool = DataToolManager.Instance.GetDataTool<BasePveSkillDataTool>();

        var skill = skillDataTool.FindSkillById(1);
        if (skill != null)
        {
            Debug.Log($"Skill found: {skill.SkillName}");
        }
        else
        {
            Debug.Log("Skill not found.");
        }

        var skills = skillDataTool.FindSkillsById(101);
        if (skills != null && skills.Count > 0)
        {
            foreach (var s in skills)
            {
                Debug.Log($"Skill: {s.SkillName}");
            }
        }
        else
        {
            Debug.Log("No skills found for the given ID.");
        }

       
    }

    private void OnUserDataLoaded()
    {
        UserEmployerDataTool useremployeTool = DataToolManager.Instance.GetDataTool<UserEmployerDataTool>();
        var test1 = useremployeTool.FindEmployerById(1);
        if (test1 != null)
        {
            testtext.text = $"name:{test1.employ_name}  id:{test1.id}  usebyfindid";
            
            text_3.text = test1.types[0];
        }

    }
}
